home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / nt / emacssrc.zip / EMACSSRC.TAR / emacs-19.17 / lisp / font-lock.el < prev    next >
Lisp/Scheme  |  1993-07-09  |  22KB  |  591 lines

  1. ;; Electric Font Lock Mode
  2. ;; Copyright (C) 1992, 1993 Free Software Foundation, Inc.
  3.  
  4. ;; Author: jwz, then rms
  5. ;; Maintainer: FSF
  6. ;; Keywords: languages, faces
  7.  
  8. ;; This file is part of GNU Emacs.
  9.  
  10. ;; GNU Emacs is free software; you can redistribute it and/or modify
  11. ;; it under the terms of the GNU General Public License as published by
  12. ;; the Free Software Foundation; either version 2, or (at your option)
  13. ;; any later version.
  14.  
  15. ;; GNU Emacs is distributed in the hope that it will be useful,
  16. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  18. ;; GNU General Public License for more details.
  19.  
  20. ;; You should have received a copy of the GNU General Public License
  21. ;; along with GNU Emacs; see the file COPYING.  If not, write to
  22. ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  23.  
  24.  
  25. ;;; Commentary:
  26.  
  27. ;; Font-lock-mode is a minor mode that causes your comments to be 
  28. ;; displayed in one face, strings in another, reserved words in another,
  29. ;; documentation strings in another, and so on.
  30. ;;
  31. ;; Comments will be displayed in `font-lock-comment-face'.
  32. ;; Strings will be displayed in `font-lock-string-face'.
  33. ;; Doc strings will be displayed in `font-lock-doc-string-face'.
  34. ;; Function and variable names (in their defining forms) will be
  35. ;;  displayed in `font-lock-function-name-face'.
  36. ;; Reserved words will be displayed in `font-lock-keyword-face'.
  37. ;;
  38. ;; To make the text you type be fontified, use M-x font-lock-mode.
  39. ;; When this minor mode is on, the fonts of the current line are
  40. ;; updated with every insertion or deletion.
  41. ;;
  42. ;; To define new reserved words or other patterns to highlight, use
  43. ;; the `font-lock-keywords' variable.  This should be mode-local.
  44. ;;
  45. ;; To turn this on automatically, add this to your .emacs file:
  46. ;;
  47. ;;    (setq emacs-lisp-mode-hook '(lambda () (font-lock-mode 1)))
  48. ;;
  49. ;; On a Sparc2, the initial fontification takes about 12 seconds for a 120k
  50. ;; file of C code, using the default configuration.  You can speed this up
  51. ;; substantially by removing some of the patterns that are highlighted by
  52. ;; default.  Fontifying Lisp code is significantly faster, because Lisp has a
  53. ;; more regular syntax than C, so the expressions don't have to be as hairy.
  54.  
  55. ;;; Code:
  56.  
  57. (or (internal-find-face 'underline)
  58.     (copy-face 'default 'underline))
  59. (set-face-underline-p 'underline t)
  60.  
  61. (defvar font-lock-comment-face
  62.   'italic
  63.   "Face to use for comments.")
  64.  
  65. (defvar font-lock-doc-string-face
  66.   'italic
  67.   "Face to use for documentation strings.")
  68.  
  69. (defvar font-lock-string-face
  70.   'underline
  71.   "Face to use for string constants.")
  72.  
  73. (defvar font-lock-function-face
  74.   'bold-italic
  75.   "Face to use for function names.")
  76.  
  77. (defvar font-lock-keyword-face
  78.   'bold
  79.   "Face to use for keywords.")
  80.  
  81. (defvar font-lock-type-face
  82.   'italic
  83.   "Face to use for data types.")
  84.  
  85. (make-variable-buffer-local 'font-lock-keywords)
  86. (defvar font-lock-keywords nil
  87.   "*The keywords to highlight.
  88. If this is a list, then elements may be of the forms:
  89.  
  90.   \"string\"              ; a regexp to highlight in the 
  91.                   ;  `font-lock-keyword-face'.
  92.   (\"string\" . integer)        ; match N of the regexp will be highlighted
  93.   (\"string\" . face-name)      ; use the named face
  94.   (\"string\" integer face-name)    ; both of the above
  95.   (\"string\" integer face-name t)  ; this allows highlighting to overlap
  96.                   ;  with already-highlighted regions.
  97.  
  98. These regular expressions should not match text which spans lines.
  99. While \\[font-lock-fontify-buffer] handles multi-line patterns correctly,
  100. updating when you edit the buffer does not,
  101. since it considers text one line at a time.
  102.  
  103. Be careful composing regexps for this list; the wrong pattern can dramatically
  104. slow things down!")
  105.  
  106. (defvar font-lock-keywords-case-fold-search nil
  107.   "*Non-nil means the patterns in `font-lock-keywords' are case-insensitive.")
  108.  
  109. (defvar font-lock-verbose t
  110.   "*Non-nil means `font-lock-fontify-buffer' should print status messages.")
  111.  
  112. ;;;###autoload
  113. (defvar font-lock-mode-hook nil
  114.   "Function or functions to run on entry to Font Lock mode.")
  115.  
  116. ;;; These variables record, for each buffer,
  117. ;;; the parse state at a particular position, always the start of a line.
  118. ;;; This is used to make font-lock-fontify-region faster.
  119. (defvar font-lock-cache-position nil)
  120. (defvar font-lock-cache-state nil)
  121. (make-variable-buffer-local 'font-lock-cache-position)
  122. (make-variable-buffer-local 'font-lock-cache-state)
  123.  
  124. (defun font-lock-fontify-region (start end)
  125.   "Put proper face on each string and comment between START and END."
  126.   (save-excursion
  127.     (goto-char start)
  128.     (beginning-of-line)
  129.     (setq end (min end (point-max)))
  130.     (let (state startline prev prevstate)
  131.       ;; Find the state at the line-beginning before START.
  132.       (setq startline (point))
  133.       (if (eq (point) font-lock-cache-position)
  134.       (setq state font-lock-cache-state)
  135.     ;; Find outermost containing sexp.
  136.     (beginning-of-defun)
  137.     ;; Find the state at STARTLINE.
  138.     (while (< (point) startline)
  139.       (setq state (parse-partial-sexp (point) startline 0)))
  140.     (setq font-lock-cache-state state
  141.           font-lock-cache-position (point)))
  142.       ;; Now find the state precisely at START.
  143.       (setq state (parse-partial-sexp (point) start nil nil state))
  144.       ;; If the region starts inside a string, show the extent of it.
  145.       (if (nth 3 state)
  146.       (let ((beg (point)))
  147.         (while (and (re-search-forward "\\s\"" end 'move)
  148.             (nth 3 (parse-partial-sexp beg (point)
  149.                            nil nil state))))
  150.         (put-text-property beg (point) 'face font-lock-string-face)
  151.         (setq state (parse-partial-sexp beg (point) nil nil state))))
  152.       ;; Likewise for a comment.
  153.       (if (or (nth 4 state) (nth 7 state))
  154.       (let ((beg (point)))
  155.         (while (and (re-search-forward (if comment-end
  156.                            (concat "\\s>\\|"
  157.                                (regexp-quote comment-end))
  158.                          "\\s>")
  159.                        end 'move)
  160.             (nth 3 (parse-partial-sexp beg (point)
  161.                            nil nil state))))
  162.         (put-text-property beg (point) 'face font-lock-comment-face)
  163.         (setq state (parse-partial-sexp beg (point) nil nil state))))
  164.       ;; Find each interesting place between here and END.
  165.       (while (and (< (point) end)
  166.           (setq prev (point) prevstate state)
  167.           (re-search-forward (concat "\\s\"\\|" (regexp-quote comment-start)) end t)
  168.           ;; Clear out the fonts of what we skip over.
  169.           (progn (remove-text-properties prev (point) '(face nil)) t)
  170.           ;; Verify the state at that place
  171.           ;; so we don't get fooled by \" or \;.
  172.           (setq state (parse-partial-sexp prev (point)
  173.                           nil nil state)))
  174.     (let ((here (point)))
  175.       (if (or (nth 4 state) (nth 7 state))
  176.           ;; We found a real comment start.
  177.           (let ((beg (match-beginning 0)))
  178.         (goto-char beg)
  179.         (save-restriction
  180.           (narrow-to-region (point-min) end)
  181.           (condition-case nil
  182.               (progn
  183.             (forward-comment 1)
  184.             ;; forward-comment skips all whitespace,
  185.             ;; so go back to the real end of the comment.
  186.             (skip-chars-backward " \t"))
  187.             (error (goto-char end))))
  188.         (put-text-property beg (point) 'face font-lock-comment-face)
  189.         (setq state (parse-partial-sexp here (point) nil nil state)))
  190.         (if (nth 3 state)
  191.         (let ((beg (match-beginning 0)))
  192.           (while (and (re-search-forward "\\s\"" end 'move)
  193.                   (nth 3 (parse-partial-sexp here (point)
  194.                              nil nil state))))
  195.           (put-text-property beg (point) 'face font-lock-string-face)
  196.           (setq state (parse-partial-sexp here (point) nil nil state))))
  197.           ))
  198.     ;; Make sure PREV is non-nil after the loop
  199.     ;; only if it was set on the very last iteration.
  200.     (setq prev nil))
  201.       (and prev
  202.        (remove-text-properties prev end '(face nil))))))
  203.  
  204. ;; This code used to be used to show a string on reaching the end of it.
  205. ;; It is probably not needed due to later changes to handle strings
  206. ;; starting before the region in question.
  207. ;;        (if (and (null (nth 3 state))
  208. ;;             (eq (char-syntax (preceding-char)) ?\")
  209. ;;             (save-excursion
  210. ;;               (nth 3 (parse-partial-sexp prev (1- (point))
  211. ;;                          nil nil prevstate))))
  212. ;;        ;; We found the end of a string.
  213. ;;        (save-excursion
  214. ;;          (setq foo2 (point))
  215. ;;          (let ((ept (point)))
  216. ;;            (forward-sexp -1)
  217. ;;            ;; Highlight the string when we see the end.
  218. ;;            ;; Doing it at the start leads to trouble:
  219. ;;            ;; either it fails to handle multiline strings
  220. ;;            ;; or it can run away when an unmatched " is inserted.
  221. ;;            (put-text-property (point) ept 'face
  222. ;;                       (if (= (car state) 1)
  223. ;;                       font-lock-doc-string-face
  224. ;;                     font-lock-string-face)))))
  225.  
  226. (defun font-lock-unfontify-region (beg end)
  227.   (remove-text-properties beg end '(face nil)))
  228.  
  229. ;; Called when any modification is made to buffer text.
  230. (defun font-lock-after-change-function (beg end old-len)
  231.   (save-excursion
  232.     (save-match-data
  233.       (goto-char beg)
  234.       ;; Discard the cache info if text before it has changed.
  235.       (and font-lock-cache-position
  236.        (> font-lock-cache-position beg)
  237.        (setq font-lock-cache-position nil))
  238.       ;; Rescan till end of line.  yes!
  239.       (goto-char end)
  240.       (end-of-line)
  241.       (setq end (point))
  242.       ;; First scan for strings and comments.
  243.       (font-lock-fontify-region beg (1+ end))
  244.       (goto-char beg)
  245.       (beginning-of-line)
  246.       (setq beg (point))
  247.       ;; Now scan for keywords.
  248.       (font-lock-hack-keywords beg end))))
  249.  
  250. ;;; Fontifying arbitrary patterns
  251.  
  252. (defsubst font-lock-any-properties-p (start end)
  253.   (or (get-text-property start 'font-lock)
  254.       (let ((next (next-single-property-change start 'font-lock)))
  255.     (and next (< next end)))))
  256.  
  257. (defun font-lock-hack-keywords (start end &optional loudly)
  258.   (goto-char start)
  259.   (let ((case-fold-search font-lock-keywords-case-fold-search)
  260.     (rest font-lock-keywords)
  261.     (count 0)
  262.     first str match face s e allow-overlap-p)
  263.     (while rest
  264.       (setq first (car rest) rest (cdr rest))
  265.       (goto-char start)
  266.       (cond ((consp first)
  267.          (setq str (car first))
  268.          (cond ((consp (cdr first))
  269.             (setq match (nth 1 first)
  270.               face (nth 2 first)
  271.               allow-overlap-p (nth 3 first)))
  272.            ((symbolp (cdr first))
  273.             (setq match 0 allow-overlap-p nil
  274.               face (cdr first)))
  275.            (t
  276.             (setq match (cdr first)
  277.               allow-overlap-p nil
  278.               face font-lock-keyword-face))))
  279.         (t
  280.          (setq str first match 0 allow-overlap-p nil
  281.            face font-lock-keyword-face)))
  282.       ;(message "regexp: %s" str)
  283.       (while (re-search-forward str end t)
  284.     (setq s (match-beginning match)
  285.           e (match-end match))
  286.     (or s (error "expression did not match subexpression %d" match))
  287.     ;; don't fontify this keyword if we're already in some other context.
  288.     (or (if allow-overlap-p nil (font-lock-any-properties-p s e))
  289.         (progn
  290.           (put-text-property s e 'face face))))
  291.       (if loudly (message "Fontifying %s... (regexps...%s)"
  292.               (buffer-name)
  293.               (make-string (setq count (1+ count)) ?.))))))
  294.  
  295.  
  296. ;; The user level functions
  297.  
  298. (defvar font-lock-mode nil) ; for modeline
  299. (or (assq 'font-lock-mode minor-mode-alist)
  300.     (setq minor-mode-alist
  301.       (append minor-mode-alist
  302.           '((font-lock-mode " Font")))))
  303.  
  304. (defvar font-lock-fontified nil) ; whether we have hacked this buffer
  305. (put 'font-lock-fontified 'permanent-local t)
  306.  
  307. ;;;###autoload
  308. (defun font-lock-mode (&optional arg)
  309.   "Toggle Font Lock mode.
  310. With arg, turn Font Lock mode on if and only if arg is positive.
  311.  
  312. When Font Lock mode is enabled, text is fontified as you type it:
  313.  
  314.  - comments are displayed in `font-lock-comment-face';
  315.      (That is a variable whose value should be a face name.)
  316.  - strings are displayed in `font-lock-string-face';
  317.  - documentation strings are displayed in `font-lock-doc-string-face';
  318.  - function and variable names in their defining forms are displayed
  319.    in `font-lock-function-name-face';
  320.  - and certain other expressions are displayed in other faces
  321.    according to the value of the variable `font-lock-keywords'.
  322.  
  323. When you turn Font Lock mode on/off, the buffer is fontified/defontified.
  324. To fontify a buffer without having newly typed text become fontified, you
  325. can use \\[font-lock-fontify-buffer]."
  326.   (interactive "P")
  327.   (let ((on-p (if (null arg)
  328.           (not font-lock-mode)
  329.         (> (prefix-numeric-value arg) 0))))
  330.     (if (equal (buffer-name) " *Compiler Input*") ; hack for bytecomp...
  331.     (setq on-p nil))
  332.     (or (memq after-change-function
  333.           '(nil font-lock-after-change-function))
  334.     (error "after-change-function is %s" after-change-function))
  335.     (set (make-local-variable 'after-change-function)
  336.      (if on-p 'font-lock-after-change-function nil))
  337.     (set (make-local-variable 'font-lock-mode) on-p)
  338.     (cond (on-p
  339.        (font-lock-set-defaults)
  340.        (run-hooks 'font-lock-mode-hook)
  341.        (or font-lock-fontified (font-lock-fontify-buffer)))
  342.       (font-lock-fontified
  343.        (setq font-lock-fontified nil)
  344.        (font-lock-unfontify-region (point-min) (point-max))))
  345.     (force-mode-line-update)))
  346.  
  347.  
  348. (defun font-lock-fontify-buffer ()
  349.   "Fontify the current buffer the way `font-lock-mode' would:
  350.  
  351.  - comments are displayed in `font-lock-comment-face';
  352.  - strings are displayed in `font-lock-string-face';
  353.  - documentation strings are displayed in `font-lock-doc-string-face';
  354.  - function and variable names in their defining forms are displayed
  355.    in `font-lock-function-name-face';
  356.  - and certain other expressions are displayed in other faces
  357.    according to the value of the variable `font-lock-keywords'.
  358.  
  359. This can take a while for large buffers."
  360.   (interactive)
  361.   (let ((was-on font-lock-mode)
  362.     (font-lock-verbose (or font-lock-verbose (interactive-p))))
  363.     (if font-lock-verbose (message "Fontifying %s..." (buffer-name)))
  364.     ;; Turn it on to run hooks and get the right font-lock-keywords.
  365.     (or was-on (font-lock-mode 1))
  366.     (font-lock-unfontify-region (point-min) (point-max))
  367.     (if font-lock-verbose (message "Fontifying %s... (syntactically...)"
  368.                    (buffer-name)))
  369. ;;    (buffer-syntactic-context-flush-cache)
  370.     (save-excursion
  371.       (font-lock-fontify-region (point-min) (point-max))
  372.       (if font-lock-verbose (message "Fontifying %s... (regexps...)"
  373.                      (buffer-name)))
  374.       (font-lock-hack-keywords (point-min) (point-max) font-lock-verbose))
  375.     (or was-on (font-lock-mode 0)) ; turn it off if it was off.
  376.     (set (make-local-variable 'font-lock-fontified) t)
  377.     (if font-lock-verbose (message "Fontifying %s... done." (buffer-name)))
  378.     ))
  379.  
  380.  
  381. ;;; Various mode-specific information.
  382.  
  383. (defun font-lock-set-defaults ()
  384.   "sets font-lock-keywords to something appropriate for this mode."
  385.   (setq font-lock-keywords
  386.     (cond ((eq major-mode 'lisp-mode)    lisp-font-lock-keywords)
  387.           ((eq major-mode 'emacs-lisp-mode)    lisp-font-lock-keywords)
  388.           ((eq major-mode 'c-mode)        c-font-lock-keywords)
  389.           ((eq major-mode 'c++-c-mode)    c-font-lock-keywords)
  390.           ((eq major-mode 'c++-mode)    c++-font-lock-keywords)
  391.           ((eq major-mode 'perl-mode)    perl-font-lock-keywords)
  392.           ((eq major-mode 'tex-mode)    tex-font-lock-keywords)
  393.           ((eq major-mode 'texinfo-mode)    texi-font-lock-keywords)
  394.           (t nil))))
  395.  
  396. (defconst lisp-font-lock-keywords-1
  397.  '(;;
  398.    ;; highlight defining forms.  This doesn't work too nicely for
  399.    ;; (defun (setf foo) ...) but it does work for (defvar foo) which
  400.    ;; is more important.
  401.    ("^(def[-a-z]+\\s +\\([^ \t\n\)]+\\)" 1 font-lock-function-name-face)
  402.    ;;
  403.    ;; highlight CL keywords
  404.    ("\\s :\\(\\(\\sw\\|\\s_\\)+\\)\\>" . 1)
  405.    ;;
  406.    ;; this is highlights things like (def* (setf foo) (bar baz)), but may
  407.    ;; be slower (I haven't really thought about it)
  408. ;   ("^(def[-a-z]+\\s +\\(\\s(\\S)*\\s)\\|\\S(\\S *\\)"
  409. ;    1 font-lock-function-name-face)
  410.    )
  411.  "For consideration as a value of `lisp-font-lock-keywords'.
  412. This does fairly subdued highlighting.")
  413.  
  414. (defconst lisp-font-lock-keywords-2
  415.   (append
  416.    lisp-font-lock-keywords-1
  417.    '(;;
  418.      ;; Highlight control structures
  419.      ("(\\(cond\\|if\\|when\\|unless\\|[ec]?\\(type\\)?case\\)[ \t\n]" . 1)
  420.      ("(\\(while\\|do\\|let*?\\|flet\\|labels\\|prog[nv12*]?\\)[ \t\n]" . 1)
  421.      ("(\\(catch\\|\\throw\\|block\\|return\\|return-from\\)[ \t\n]" . 1)
  422.      ("(\\(save-restriction\\|save-window-restriction\\)[ \t\n]" . 1)
  423.      ("(\\(save-excursion\\|unwind-protect\\|condition-case\\)[ \t\n]" . 1)
  424.      ;;
  425.      ;; highlight function names in emacs-lisp docstrings (in the syntax
  426.      ;; that substitute-command-keys understands.)
  427.      ("\\\\\\\\\\[\\([^]\\\n]+\\)]" 1 font-lock-keyword-face t)
  428.      ;;
  429.      ;; highlight words inside `' which tend to be function names
  430.      ("`\\([-a-zA-Z0-9_][-a-zA-Z0-9_][-a-zA-Z0-9_.]+\\)'"
  431.       1 font-lock-keyword-face t)
  432.      ))
  433.  "For consideration as a value of `lisp-font-lock-keywords'.
  434. This does a lot more highlighting.")
  435.  
  436. ;; default to the gaudier variety?
  437. ;(defvar lisp-font-lock-keywords lisp-font-lock-keywords-2
  438. ;  "Additional expressions to highlight in Lisp modes.")
  439. (defvar lisp-font-lock-keywords lisp-font-lock-keywords-1
  440.   "Additional expressions to highlight in Lisp modes.")
  441.  
  442.  
  443. (defconst c-font-lock-keywords-1 nil
  444.  "For consideration as a value of `c-font-lock-keywords'.
  445. This does fairly subdued highlighting.")
  446.  
  447. (defconst c-font-lock-keywords-2 nil
  448.  "For consideration as a value of `c-font-lock-keywords'.
  449. This does a lot more highlighting.")
  450.  
  451. (let ((storage "auto\\|extern\\|register\\|static\\|volatile")
  452.       (prefixes "unsigned\\|short\\|long")
  453.       (types (concat "int\\|char\\|float\\|double\\|void\\|struct\\|"
  454.              "union\\|enum\\|typedef"))
  455.       (ctoken "[a-zA-Z0-9_:~*]+")
  456.       )
  457.   (setq c-font-lock-keywords-1
  458.    (list
  459.     ;; fontify preprocessor directives as comments.
  460.     '("^#[ \t]*[a-z]+" . font-lock-comment-face)
  461.     ;;
  462.     ;; fontify names being defined.
  463.     '("^#[ \t]*\\(define\\|undef\\)[ \t]+\\(\\(\\sw\\|\\s_\\)+\\)" 2
  464.       font-lock-function-name-face)
  465.     ;;
  466.     ;; fontify other preprocessor lines.
  467.     '("^#[ \t]*\\(if\\|ifn?def\\)[ \t]+\\([^\n]+\\)"
  468.       2 font-lock-function-name-face t)
  469.     ;;
  470.     ;; fontify the filename in #include <...>
  471.     ;; don't need to do this for #include "..." because those were
  472.     ;; already fontified as strings by the syntactic pass.
  473.     '("^#[ \t]*include[ \t]+\\(<[^>\"\n]+>\\)" 1 font-lock-string-face)
  474.     ;;
  475.     ;; fontify the names of functions being defined.
  476.     (list (concat
  477.        "^\\(" ctoken "[ \t]+\\)?"    ; type specs; there can be no
  478.        "\\(" ctoken "[ \t]+\\)?"    ; more than 3 tokens, right?
  479.        "\\(" ctoken "[ \t]+\\)?"
  480.        "\\(\\*+[ \t]*\\)?"        ; pointer
  481.        "\\(" ctoken "\\)[ \t]*(")        ; name
  482.       5 'font-lock-function-name-face)
  483.     ;;
  484.     ;;
  485.     ;; Fontify structure names (in structure definition form).
  486.     (list (concat "^\\(typedef[ \t]+struct\\|struct\\|static[ \t]+struct\\)"
  487.           "[ \t]+\\(" ctoken "\\)[ \t]*\\(\{\\|$\\)")
  488.       2 'font-lock-function-name-face)
  489.     ;;
  490.     ;; Fontify case clauses.  This is fast because its anchored on the left.
  491.     '("case[ \t]+\\(\\(\\sw\\|\\s_\\)+\\):". 1)
  492.     '("\\<\\(default\\):". 1)
  493.     ))
  494.  
  495.   (setq c-font-lock-keywords-2
  496.    (append c-font-lock-keywords-1
  497.     (list
  498.      ;;
  499.      ;; fontify all storage classes and type specifiers
  500.      (cons (concat "\\<\\(" storage "\\)\\>") 'font-lock-type-face)
  501.      (cons (concat "\\<\\(" types "\\)\\>") 'font-lock-type-face)
  502.      (cons (concat "\\<\\(" prefixes "[ \t]+" types "\\)\\>")
  503.        'font-lock-type-face)
  504.      ;;
  505.      ;; fontify all builtin tokens
  506.      (cons (concat
  507.         "[ \t]\\("
  508.         (mapconcat 'identity
  509.          '("for" "while" "do" "return" "goto" "case" "break" "switch"
  510.            "if" "then" "else if" "else" "return" "default" "continue"
  511.            "default"
  512.            )
  513.          "\\|")
  514.         "\\)[ \t\n(){};,]")
  515.        1)
  516.      ;;
  517.      ;; fontify case targets and goto-tags.  This is slow because the
  518.      ;; expression is anchored on the right.
  519.      "\\(\\(\\sw\\|\\s_\\)+\\):"
  520.      ;;
  521.      ;; Fontify variables declared with structures, or typedef names.
  522.      '("}[ \t*]*\\(\\(\\sw\\|\\s_\\)+\\)[ \t]*[,;]"
  523.        1 font-lock-function-name-face)
  524.      ;;
  525.      ;; Fontify global variables without a type.
  526. ;     '("^\\([_a-zA-Z0-9:~*]+\\)[ \t]*[[;={]" 1 font-lock-function-name-face)
  527.  
  528.      )))
  529.   )
  530.  
  531. ; default to the gaudier variety?
  532. ;(defvar c-font-lock-keywords c-font-lock-keywords-2
  533. ;  "Additional expressions to highlight in C mode.")
  534. (defvar c-font-lock-keywords c-font-lock-keywords-1
  535.   "Additional expressions to highlight in C mode.")
  536.  
  537. (defvar c++-font-lock-keywords c-font-lock-keywords
  538.   "Additional expressions to highlight in C++ mode.")
  539.  
  540.  
  541. (defvar perl-font-lock-keywords
  542.   (list
  543.    (concat "[ \n\t{]*\\("
  544.        (mapconcat 'identity
  545.               '("if" "until" "while" "elsif" "else" "unless" "for"
  546.             "foreach" "continue" "exit" "die" "last" "goto" "next"
  547.             "redo" "return" "local" "exec")
  548.               "\\|")
  549.        "\\)[ \n\t;(]")
  550.    (mapconcat 'identity
  551.           '("#endif" "#else" "#ifdef" "#ifndef" "#if" "#include"
  552.         "#define" "#undef")
  553.           "\\|")
  554.    '("^[ \n\t]*sub[ \t]+\\([^ \t{]+\\)\\{" . font-lock-function-name-face)
  555.    '("[ \n\t{]*\\(eval\\)[ \n\t(;]" . font-lock-function-name-face)
  556.    '("\\(--- .* ---\\|=== .* ===\\)" . font-lock-doc-string-face)
  557.    )
  558.   "Additional expressions to highlight in Perl mode.")
  559.  
  560. (defvar tex-font-lock-keywords
  561.   (list
  562.    '("\\(\\\\\\w+\\)" 1 font-lock-keyword-face t)
  563.    '("{\\\\em\\([^}]+\\)}" 1 font-lock-comment-face t)
  564.    '("{\\\\bf\\([^}]+\\)}" 1 font-lock-keyword-face t)
  565.    '("^[ \t\n]*\\\\def[\\\\@]\\(\\w+\\)" 1 font-lock-function-name-face t)
  566.    '("\\\\\\(begin\\|end\\){\\([a-zA-Z0-9\\*]+\\)}"
  567.      2 font-lock-function-name-face t)
  568.    '("[^\\\\]\\$\\([^$]*\\)\\$" 1 font-lock-string-face t)
  569. ;   '("\\$\\([^$]*\\)\\$" 1 font-lock-string-face t)
  570.    )
  571.   "Additional expressions to highlight in TeX mode.")
  572.  
  573. (defvar texi-font-lock-keywords
  574.   (list
  575.    "@\\(@\\|[^}\t \n{]+\\)"                    ;commands
  576.    '("^\\(@c\\|@comment\\)[ \t].*$" . font-lock-comment-face)    ;comments
  577.    '("^\\(*.*\\)[\t ]*$" 1 font-lock-function-name-face t)    ;menu items
  578.    '("@\\(emph\\|strong\\|b\\|i\\){\\([^}]+\\)" 2 font-lock-comment-face t)
  579.    '("@\\(file\\|kbd\\|key\\){\\([^}]+\\)" 2 font-lock-string-face t)
  580.    '("@\\(samp\\|code\\|var\\){\\([^}]+\\)" 2 font-lock-function-name-face t)
  581.    '("@\\(xref\\|pxref\\){\\([^}]+\\)" 2 font-lock-keyword-face t)
  582.    '("@end *\\([a-zA-Z0-9]+\\)[ \t]*$" 1 font-lock-function-name-face t)
  583.    '("@item \\(.*\\)$" 1 font-lock-function-name-face t)
  584.    '("\\$\\([^$]*\\)\\$" 1 font-lock-string-face t)
  585.    )
  586.   "Additional expressions to highlight in TeXinfo mode.")
  587.  
  588. (provide 'font-lock)
  589.  
  590. ;;; font-lock.el ends here
  591.